﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.LinqToSqlProvider;
using MvcEngine.Core.Repositories;
using MvcEngine.Core.Models.Entities;

namespace MvcEngine.CustomizationTest
{
    public class UserRepositoryCustomization : IUserRepository
    {

        #region IUserRepository Members

        public IUser Get(string name)
        {
            using (MvcCustomizationDataContext context = new MvcCustomizationDataContext()) 
            {
                return context.Users.FirstOrDefault(t => t.Name == name);
            }
        }

        public IUser GetHostUser(string name)
        {
            using (MvcCustomizationDataContext context = new MvcCustomizationDataContext())
            {
                IUser user = context.Users.FirstOrDefault(u => u.Name == name);
                if (user != null)
                {
                    if (user.IsHost)
                    {
                        return user;
                    }
                }
            }
            return null;
        }

        public bool ValidateUser(string userName, string password)
        {
            return true;
        }

        #endregion

        #region IBaseRepository<IUser> Members

        public IUser Get(int id)
        {
            using (MvcCustomizationDataContext context = new MvcCustomizationDataContext())
            {
                return context.Users.Single(t => t.Id == id);
            }
        }

        public List<MvcEngine.Core.Models.Entities.IUser> GetAll()
        {
            throw new NotImplementedException();
        }

        public void Add(MvcEngine.Core.Models.Entities.IUser entity)
        {
            using (MvcCustomizationDataContext context = new MvcCustomizationDataContext())
            {
                context.Users.InsertOnSubmit((User)entity);
                context.SubmitChanges();
            }
        }

        public void Delete(int id)
        {
            throw new NotImplementedException();
        }

        public void DeleteAll()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IUserRepository Members


        public IUser GetUserByCreateKey(Guid value)
        {
            throw new NotImplementedException();
        }

        public IUser GetUserByRestoreKey(Guid value)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IUserRepository Members


        public void Update(IUser user)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
